package ex304.bank;

public class CreditAccount extends Account {
    private double limit; // 透支限额

    public CreditAccount(String id, String name) {
        this(id, name, 0.0, 1000.0);
    }

    public CreditAccount(String id, String name, double limit) {
        this(id, name, 0.0, limit);
    }

    public CreditAccount(String id, String name, double balance, double limit) {
        super(id, name, balance);
        this.limit = limit;
    }

    @Override
    public String toString() {
        return String.format("[%s, %s, %.2f, %.2f]", id, name, balance, limit);
    }

    @Override
    public boolean withdraw(double amount) {
        if (amount > balance + limit) {
            return false;
        } else {
            balance -= amount;
            return true;
        }
    }

    public double getLimit() {
        return limit;
    }

    public void setLimit(double limit) {
        this.limit = limit;
    }
}
